<?php

/**
 * This controller for element in all pages
 * */

class ElementsController extends AppController {

    var $name = 'Elements';
    var $uses = array();
    var $helpers = array('text');

    //var $layout = 'home';

    /*
     * about qat in home page
     * */
    function about_qat() {
        $about_qat = ClassRegistry::init('static_pages.StaticPage')->find('first', array(
            'conditions' => array(
                'StaticPage.alias' => 've-qat-group',
                'is_published' => 1,
            ),
            'fields' => array('title', 'description'),
            'contain'		=> array()
                ));
        
        if( isset($this->params['requested']) )
        {
            return $about_qat;
        }
    }

    /**
     * get menu for all page
     * 
     * */
    function get_product_category() {
        // disable view
        $this->autoRender = false;

        // products category		
        $product_category = ClassRegistry::init('products.ProductCategory')->find('all');
       
        if( isset($this->params['requested']) )
        {
            return $product_category;
        }
    }

    /**
     * get menu for all page
     * 
     * */
    function get_news_category() {
        // disable view
        $this->autoRender = false;
        /// news category		
        $news_category = ClassRegistry::init('news.NewsCategory')->find('all', array(
            'conditions' => array('NewsCategory.id !=' => '1'),
                )
        );

         if( isset($this->params['requested']) )
        {
            return $news_category;
        }
    }
    
     /**
     * get menu for all page
     * 
     * */
    function get_news_qat() {
        // disable view
        $this->autoRender = false;       
        
        $news = ClassRegistry::init('news.News')->find('all', array(
				'conditions'	=>	array(
										"Category.alias" => 'tin-hoat-dong',
										"News.is_published"	=>1
									),
                'limit' => '2',
				'order'			=> array(
										'News.news_date desc',
										'News.created desc'
									),
				'joins' => array(
					array(
						'table' => ClassRegistry::init('news.News')->hasAndBelongsToMany['Category']['joinTable'],
						'type' => 'INNER',
						'alias' => 'ReferenceCategory',
						'conditions' => array(
							"News.id = ReferenceCategory.page_id"
						)
					),
					array(
						'table' => ClassRegistry::init('news.News')->Category->table,
						'type' => 'INNER',
						'alias' => 'Category',
						'conditions' => array(
							"Category.id = ReferenceCategory.category_id"
						)
					)
				)
			)
        );

         if( isset($this->params['requested']) )
        {
            return $news;
        }
    }
    
    /**
     * get menu for all page
     * 
     * */
    function get_products($limit = 3,$special = 1) {       
        // disable view
        $this->autoRender = false;       
        $products = ClassRegistry::init('products.Product')->find('all', array(
            'conditions' => array("Product.is_published"	=>1,"Product.special"	=>1),
            'limit' => $limit,
            'order'		=> array(
    						'Product.news_date desc',
    						'Product.created desc'
    					),
            'contain'		=> array()
                )
            );
             
        if( isset($this->params['requested']) )
        {
            return $products;
        }
       
    }

}

?>
